﻿using System;

namespace SSC.PlcConnect
{
    public interface IPlcConnect
    {
        /// <summary>
        /// 尝试连接PLC
        /// </summary>
        /// <returns>是否成功连接</returns>
        Task<bool> ConnectAsync();

        /// <summary>
        /// 断开PLC连接
        /// </summary>
        void Disconnect();

        /// <summary>
        /// 读取PLC数据（单个地址）
        /// </summary>
        /// <param name="address">PLC地址</param>
        /// <returns>读取单个值</returns>
        Task<short> ReadSingle(string address);

        /// <summary>
        /// 批量读取PLC数据（连续地址）
        /// </summary>
        /// <param name="startAddress">起始地址</param>
        /// <param name="length">读取的长度</param>
        /// <returns>读取的值数组</returns>
        Task<short[]> ReadBatch(string address, ushort length);

        /// <summary>
        /// 写入PLC数据（单个地址）
        /// </summary>
        /// <param name="address">PLC地址</param>
        /// <param name="value">要写入的值</param>
        Task<bool> WriteSingle(string address, short value);

        /// <summary>
        /// 批量写入PLC数据（连续地址）
        /// </summary>
        /// <param name="startAddress">起始地址</param>
        /// <param name="values">要写入的值数组</param>
        Task<bool> WriteBatch(string address, short[] values);

        /// <summary>
        /// 读取PLC布尔值（单个地址）
        /// </summary>
        /// <param name="address">PLC地址</param>
        /// <returns>读取的布尔值</returns>
        Task<bool> ReadBool(string address);

        /// <summary>
        /// 批量读取PLC布尔值（连续地址）
        /// </summary>
        /// <param name="address">起始地址</param>
        /// <param name="length">读取的长度</param>
        /// <returns>布尔值数组</returns>
        Task<bool[]> ReadBoolBatch(string address, ushort length);

    }
}
